package com.epsoft.odin7cj.flow.example;

import java.util.List;
import java.util.UUID;

import org.activiti.engine.IdentityService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.identity.User;

/**
 * 用户操作
 * @author Administrator
 *
 */
public class C03User {

	public static void main1(String[] args) {
		
		// 流程引擎
		ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
		
		// 获取身份服务
		IdentityService ids= engine.getIdentityService();
		
		// 创建用户
		creatUser(ids, "四", "李", "test@163.com", "123456");
		
		List<User> listUser = ids.createUserQuery().list();
		for(User user : listUser) {
			System.out.println("\n user name:"+user.getFirstName());
		}
		
	}
	
	//创建用户方法
	static void creatUser(IdentityService identityService,String first, String last, String email, String passwd) {
		// 使用newUser方法创建User实例
		User user = identityService.newUser(UUID.randomUUID().toString());
		// 设置用户的各个属性
		user.setFirstName(first);
		user.setLastName(last);
		user.setEmail(email);
		user.setPassword(passwd);
		// 使用saveUser方法保存用户
		identityService.saveUser(user);
	}
}
